import { getWithErrorMessage, putWithErrorMessage, postWithErrorMessage } from '@/utils/http/Axios'

export function fetchCaptcha() {
    return postWithErrorMessage<Captcha>('/base/api/v1/captcha/image').then(resp => resp.data)
}

export function login(loginForm: LoginForm): Promise<LoginResponse> {
    return postWithErrorMessage<LoginResponse>('/base/api/v1/login', loginForm).then(resp => resp.data)
}

export function mobileLogin(loginForm: MobileLoginForm): Promise<LoginResponse> {
    return postWithErrorMessage<LoginResponse>('base/api/v1/login/password', loginForm).then(resp => resp.data)
}

export function fetchUserInfo(): Promise<UserInfoResponse> {
    return getWithErrorMessage<UserInfoResponse>('/base/api/v1/user/userinfo').then(resp => resp.data)
}

export function updatePassword(form: { mobile: string; oldPassword: string; password: string }) {
    return putWithErrorMessage('/base/api/v1/user/password/old_password', form).then(resp => resp.data)
}

export const fetchSystemInfo = async (url: string) => {
    return postWithErrorMessage('/base/api/v1/product/url', {
        url: url
    })
}
